<div class="col-md-12 col-sm-12 col-xs-12">
  <div class="x_panel">
    <div class="x_title">
      <h2>{$pri_name} <small></small></h2>
      <div class="clearfix"></div>
    </div>

    <div class="x_content">

      <form class="form-horizontal form-label-left" novalidate action="" id="commentForm" method="post" enctype="multipart/form-data">

        <p><code>备注:</code>{$code}</a></p>
        </p>
        <!--<span class="section">Personal Info</span>-->

        <div class="item form-group">
          <label class="control-label col-md-3 col-sm-3 col-xs-12" for="role_name">角色名称 <span class="required">*</span>
          </label>
          <div class="col-md-6 col-sm-6 col-xs-12 ">
            <input type="text" id="role_name" name="role_name" value="{$info.role_name|default=''}" minlength="2" required class="form-control col-md-7 col-xs-12" placeholder="">
          </div>
        </div>
        <div class="item form-group">
          <label class="control-label col-md-3 col-sm-3 col-xs-12" for="role_name">登录后地址 <span class="required">*</span>
          </label>
          <div class="col-md-6 col-sm-6 col-xs-12 ">
            <input type="text" id="login_url" name="login_url" value="{$info.login_url|default=''}" minlength="2" required class="form-control col-md-7 col-xs-12" placeholder="">
          </div>
        </div>
        <div class="item form-group">
          <label class="control-label col-md-3 col-sm-3 col-xs-12" for="pri_id">权限列表 <span class="required">*</span>
          </label>
          <div class="col-md-6 col-sm-6 col-xs-12 ">
            <tr>
              <td>
                {eq name="$Request.action" value="create"}
                <?php foreach ($list as $k => $v): ?>
                <?php echo str_repeat('-', 8*$v['level']); ?>
                <input level_id="<?php echo $v['level']; ?>" id="pri_id" type="checkbox" name="pri_id[]" required value="<?php echo $v['id']; ?>" />
                <?php echo $v['pri_name']; ?><br />
                <?php endforeach; ?>
                {else/}
                <?php foreach ($list as $k => $v):
                // 如何判断 ,1, 是否在 ,12,4,21,453,12, 字符串中
                // 问： strpos('1,2,3', '1');  的返回值：0 , 0 == false
                if(strpos(','.$list1.',', ','.$v['id'].',') !== FALSE)
                $check = 'checked="checked"';
                else
                $check = '';
                ?>
                <?php echo str_repeat('-', 8*$v['level']); ?>
                <input <?php echo $check; ?> level_id="<?php echo $v['level']; ?>" type="checkbox" name="pri_id[]" required id="pri_id" value="<?php echo $v['id']; ?>" />
                <?php echo $v['pri_name']; ?><br />
                <?php endforeach; ?>
                {/eq}
              </td>
            </tr>
          </div>
        </div>



        <div class="ln_solid"></div>
        <div class="form-group">
          <div class="col-md-6 col-md-offset-3">
            <button id="send" type="submit" class="btn btn-success">提交</button>
            <div class="btn btn-primary" onclick="history.go(-1)">返回</div>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>
<script>
    // 为所有的复选框绑定一个点击事件
    $(":checkbox").click(function(){
        // 先获取点击的这个level_id
        var tmp_level_id = level_id = $(this).attr("level_id");
        // 判断是选中还是取消
        if($(this).prop("checked"))
        {
            // 所有的子权限也选中
            $(this).nextAll(":checkbox").each(function(k,v){
                if($(v).attr("level_id") > level_id)
                    $(v).prop("checked", "checked");
                else
                    return false;
            });
            // 所有的上级权限也选中
            $(this).prevAll(":checkbox").each(function(k,v){
                if($(v).attr("level_id") < tmp_level_id)
                {
                    $(v).prop("checked", "checked");
                    tmp_level_id--; // 再找更上一级的
                }
            });
        }
        else
        {
            // 所有的子权限也取消
            $(this).nextAll(":checkbox").each(function(k,v){
                if($(v).attr("level_id") > level_id)
                    $(v).removeAttr("checked");
                else
                    return false;
            });
        }
    });
</script>